import { Component, enableProdMode, OnInit } from '@angular/core';
import { UserService } from './user/service/user.service';
import { HttpClient } from '@angular/common/http';
import { Result } from './user/model/result';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app';
  constructor(public userService: UserService, public http: HttpClient) {

  }

  ngOnInit() {
    // enableProdMode();
    this.http.get('/me').subscribe((result: Result) => {
      if (result.error === '') {
        this.userService.currentUser = result.data['principal'];
      }
    });
  }

  logout() {
    this.http.get('/logout').subscribe((result: Result) => {
      if (result.error === '') {
        this.userService.currentUser = null;
      }
    });
  }
}
